﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThreeByte.ActiveDeck.Config;

namespace ThreeByte.ActiveDeck.Controls
{
    /// <summary>
    /// Interaction logic for MultipleChoiceConfiguration.xaml
    /// </summary>
    public partial class MultipleChoiceConfiguration : UserControl
    {

        MultipleChoiceConfig mConfig;

        public MultipleChoiceConfiguration(PageConfig config) {
            InitializeComponent();

            DataContext = config;

            mConfig = (MultipleChoiceConfig)config;
        }

        void Answers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
            //Re-enumerate the collection prefixes.
        }

        private void AddAnswer_Click(object sender, RoutedEventArgs e) {
            //AnswerListBox.Items
            MultipleChoiceConfig mConfig = (MultipleChoiceConfig)DataContext;
            mConfig.Answers.Add(new Answer() { Text = "New Answer" });
        }

        private void AnswerListBox_PreviewKeyDown(object sender, KeyEventArgs e) {
            //Delete selected answers on delete key
            if (e.Key == Key.Delete) {
                List<Answer> toDelete = new List<Answer>();
                foreach (Answer s in AnswerListBox.SelectedItems) {
                    toDelete.Add(s);
                }
                foreach (Answer s in toDelete) {
                    MultipleChoiceConfig mConfig = (MultipleChoiceConfig)DataContext;
                    mConfig.Answers.Remove(s);
                }
            }
        }


        private void AnswersButton_Click(object sender, RoutedEventArgs e) {
            //Show QuestionFeedback dialog
            QuestionFeedbackControl newFeedbackControl = new QuestionFeedbackControl(mConfig);
            HostForm newDialog = new HostForm(newFeedbackControl);
            if(newDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                //TODO: Commit this if allowing reversion?
            }
        }


    }
}
